﻿using System;
using System.IO;
using System.Web;
using Framework;

namespace Enterprise.Admin.Handle
{
    /// <summary>
    /// 上传企业荣誉照片
    /// </summary>
    public partial class UploadHonorPicture : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            object result;
            try
            {
                var file = Request.Files["Filedata"];
                if (file == null)
                {
                    result = (new { state = false, message = "上传文件不能为空！" });
                    Response.Write(result.Serialization());
                    Response.End();
                }
                var filedata = new HttpPostedFileWrapper(Request.Files["Filedata"]);
                var uploadHelper = new UploadHelper
                {
                    PostedFile = filedata,
                    RelativePath = HonorConfig.RelativePath,
                    IsAdaptive = HonorConfig.IsAdaptive,
                    IsImage = true,
                    IsGenerateThumbnail = HonorConfig.IsGenerateThumbnail,
                    FileMaxLength = HonorConfig.ImageSize,
                    ThumbnailHeight = HonorConfig.ThumbnailHeight,
                    ThumbnailWidth = HonorConfig.ThumbnailWidth,
                    ThumbnailPrefix = HonorConfig.ThumbnailPrefix
                };
                if (!uploadHelper.Save())
                {
                    throw new Exception(uploadHelper.ErrorMessage);
                }
                string fileName = uploadHelper.FileName;
                string thumFileName = uploadHelper.ThumbnailFileName;
                result = (new { state = true, message = "上传成功！", fileName, thumFileName });
            }
            catch (Exception ex)
            {
                result = (new { state = false, message = ex.Message });
            }
            Response.Write(result.Serialization());
            Response.End();

        }
    }
}